using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Security.Permissions;
using System.Web;

using PickGold.Charting.Utilities;
using PickGold.Charting.Design;

namespace PickGold.Charting
{
	[SRDescription("DescriptionAttributeLineAnnotation_LineAnnotation"), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class LineAnnotation : Annotation
	{
		private LineAnchorCapStyle _endCap;
		private bool _isInfinitive;
		private LineAnchorCapStyle _startCap;

		public LineAnnotation()
		{
			base.anchorAlignment = ContentAlignment.TopLeft;
		}

		internal virtual void AdjustLineCoordinates(ref PointF point1, ref PointF point2, ref RectangleF selectionRect)
		{
			if (this.IsInfinitive)
			{
				if (Math.Round((double)point1.X, 3) == Math.Round((double)point2.X, 3))
				{
					point1.Y = (point1.Y < point2.Y) ? 0f : 100f;
					point2.Y = (point1.Y < point2.Y) ? 100f : 0f;
				}
				else if (Math.Round((double)point1.Y, 3) == Math.Round((double)point2.Y, 3))
				{
					point1.X = (point1.X < point2.X) ? 0f : 100f;
					point2.X = (point1.X < point2.X) ? 100f : 0f;
				}
				else
				{
					PointF empty = PointF.Empty;
					empty.Y = 0f;
					empty.X = (((0f - point1.Y) * (point2.X - point1.X)) / (point2.Y - point1.Y)) + point1.X;
					PointF tf2 = PointF.Empty;
					tf2.Y = 100f;
					tf2.X = (((100f - point1.Y) * (point2.X - point1.X)) / (point2.Y - point1.Y)) + point1.X;
					point1 = (point1.Y < point2.Y) ? empty : tf2;
					point2 = (point1.Y < point2.Y) ? tf2 : empty;
				}
			}
		}

		internal override void Paint(Chart chart, ChartGraphics graphics)
		{
			PointF empty = PointF.Empty;
			PointF anchorLocation = PointF.Empty;
			SizeF size = SizeF.Empty;
			this.GetRelativePosition(out empty, out size, out anchorLocation);
			PointF tf3 = new PointF(empty.X + size.Width, empty.Y + size.Height);
			RectangleF selectionRect = new RectangleF(empty, new SizeF(tf3.X - empty.X, tf3.Y - empty.Y));
			this.AdjustLineCoordinates(ref empty, ref tf3, ref selectionRect);
			if ((!float.IsNaN(empty.X) && !float.IsNaN(empty.Y)) && (!float.IsNaN(tf3.X) && !float.IsNaN(tf3.Y)))
			{
				bool flag = false;
				LineCap flat = LineCap.Flat;
				LineCap endCap = LineCap.Flat;
				if ((this._startCap != LineAnchorCapStyle.None) || (this._endCap != LineAnchorCapStyle.None))
				{
					flag = true;
					flat = graphics.Pen.StartCap;
					endCap = graphics.Pen.EndCap;
					if (this._startCap == LineAnchorCapStyle.Arrow)
					{
						if (this.LineWidth < 4)
						{
							int num = 3 - this.LineWidth;
							graphics.Pen.StartCap = LineCap.Custom;
							graphics.Pen.CustomStartCap = new AdjustableArrowCap((float)(this.LineWidth + num), (float)(this.LineWidth + num), true);
						}
						else
						{
							graphics.Pen.StartCap = LineCap.ArrowAnchor;
						}
					}
					else if (this._startCap == LineAnchorCapStyle.Diamond)
					{
						graphics.Pen.StartCap = LineCap.DiamondAnchor;
					}
					else if (this._startCap == LineAnchorCapStyle.Round)
					{
						graphics.Pen.StartCap = LineCap.RoundAnchor;
					}
					else if (this._startCap == LineAnchorCapStyle.Square)
					{
						graphics.Pen.StartCap = LineCap.SquareAnchor;
					}
					if (this._endCap == LineAnchorCapStyle.Arrow)
					{
						if (this.LineWidth < 4)
						{
							int num2 = 3 - this.LineWidth;
							graphics.Pen.EndCap = LineCap.Custom;
							graphics.Pen.CustomEndCap = new AdjustableArrowCap((float)(this.LineWidth + num2), (float)(this.LineWidth + num2), true);
						}
						else
						{
							graphics.Pen.EndCap = LineCap.ArrowAnchor;
						}
					}
					else if (this._endCap == LineAnchorCapStyle.Diamond)
					{
						graphics.Pen.EndCap = LineCap.DiamondAnchor;
					}
					else if (this._endCap == LineAnchorCapStyle.Round)
					{
						graphics.Pen.EndCap = LineCap.RoundAnchor;
					}
					else if (this._endCap == LineAnchorCapStyle.Square)
					{
						graphics.Pen.EndCap = LineCap.SquareAnchor;
					}
				}
				if (base.Common.ProcessModePaint)
				{
					graphics.DrawLineRel(this.LineColor, this.LineWidth, this.LineDashStyle, empty, tf3, this.ShadowColor, this.ShadowOffset);
				}
				if (base.Common.ProcessModeRegions)
				{
					using (GraphicsPath path = new GraphicsPath())
					{
						path.AddLine(graphics.GetAbsolutePoint(empty), graphics.GetAbsolutePoint(tf3));
						using (Pen pen = (Pen)graphics.Pen.Clone())
						{
							pen.DashStyle = DashStyle.Solid;
							pen.Width += 2f;
							try
							{
								path.Widen(pen);
							}
							catch (OutOfMemoryException)
							{
							}
							catch (ArgumentException)
							{
							}
						}
						base.Common.HotRegionsList.AddHotRegion(graphics, path, false, base.ReplaceKeywords(this.ToolTip), base.ReplaceKeywords(this.Url), base.ReplaceKeywords(this.MapAreaAttributes), base.ReplaceKeywords(base.PostBackValue), this, ChartElementType.Annotation);
					}
				}
				if (flag)
				{
					graphics.Pen.StartCap = flat;
					graphics.Pen.EndCap = endCap;
				}
				this.PaintSelectionHandles(graphics, selectionRect, null);
			}
		}

		[SRCategory("CategoryAttributeAppearance"), Browsable(false), DefaultValue(typeof(ContentAlignment), "MiddleCenter")]
		public override ContentAlignment Alignment
		{
			get
			{
				return base.Alignment;
			}
			set
			{
				base.Alignment = value;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Never), SRDescription("DescriptionAttributeAnchorAlignment"), DefaultValue(typeof(ContentAlignment), "TopLeft"), SRCategory("CategoryAttributeAnchor"), Browsable(false)]
		public override ContentAlignment AnchorAlignment
		{
			get
			{
				return base.AnchorAlignment;
			}
			set
			{
				base.AnchorAlignment = value;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Never), Browsable(false), SRCategory("CategoryAttributeMisc"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), SerializationVisibility(SerializationVisibility.Hidden), SRDescription("DescriptionAttributeAnnotationType"), Bindable(true)]
		public override string AnnotationType
		{
			get
			{
				return "Line";
			}
		}

		[DefaultValue(typeof(Color), ""), NotifyParentProperty(true), TypeConverter(typeof(ColorConverter)), SRCategory("CategoryAttributeAppearance"), Browsable(false), Editor(typeof(ChartColorEditor), typeof(UITypeEditor))]
		public override Color BackColor
		{
			get
			{
				return base.BackColor;
			}
			set
			{
				base.BackColor = value;
			}
		}

		[DefaultValue(0), Browsable(false), NotifyParentProperty(true), Editor(typeof(GradientEditor), typeof(UITypeEditor)), SRCategory("CategoryAttributeAppearance")]
		public override GradientStyle BackGradientStyle
		{
			get
			{
				return base.BackGradientStyle;
			}
			set
			{
				base.BackGradientStyle = value;
			}
		}

		[NotifyParentProperty(true), Editor(typeof(HatchStyleEditor), typeof(UITypeEditor)), SRCategory("CategoryAttributeAppearance"), Browsable(false), DefaultValue(0)]
		public override ChartHatchStyle BackHatchStyle
		{
			get
			{
				return base.BackHatchStyle;
			}
			set
			{
				base.BackHatchStyle = value;
			}
		}

		[NotifyParentProperty(true), Browsable(false), DefaultValue(typeof(Color), ""), TypeConverter(typeof(ColorConverter)), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), SRCategory("CategoryAttributeAppearance")]
		public override Color BackSecondaryColor
		{
			get
			{
				return base.BackSecondaryColor;
			}
			set
			{
				base.BackSecondaryColor = value;
			}
		}

		[DefaultValue(0), SRDescription("DescriptionAttributeStartCap3"), SRCategory("CategoryAttributeAppearance")]
		public virtual LineAnchorCapStyle EndCap
		{
			get
			{
				return this._endCap;
			}
			set
			{
				this._endCap = value;
				this.Invalidate();
			}
		}

		[DefaultValue(typeof(System.Drawing.Font), "Microsoft Sans Serif, 8pt"), SRCategory("CategoryAttributeAppearance"), Browsable(false)]
		public override System.Drawing.Font Font
		{
			get
			{
				return base.Font;
			}
			set
			{
				base.Font = value;
			}
		}

		[Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), Browsable(false), DefaultValue(typeof(Color), "Black"), SRCategory("CategoryAttributeAppearance"), SRDescription("DescriptionAttributeForeColor"), TypeConverter(typeof(ColorConverter))]
		public override Color ForeColor
		{
			get
			{
				return base.ForeColor;
			}
			set
			{
				base.ForeColor = value;
			}
		}

		[SRDescription("DescriptionAttributeDrawInfinitive"), DefaultValue(false), SRCategory("CategoryAttributeAppearance")]
		public virtual bool IsInfinitive
		{
			get
			{
				return this._isInfinitive;
			}
			set
			{
				this._isInfinitive = value;
				this.Invalidate();
			}
		}

		[SRDescription("DescriptionAttributeSizeAlwaysRelative3"), DefaultValue(true), SRCategory("CategoryAttributePosition")]
		public override bool IsSizeAlwaysRelative
		{
			get
			{
				return base.IsSizeAlwaysRelative;
			}
			set
			{
				base.IsSizeAlwaysRelative = value;
			}
		}

		[SRCategory("CategoryAttributeAppearance"), SRDescription("DescriptionAttributeSelectionPointsStyle"), DefaultValue(1), ParenthesizePropertyName(true), Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), SerializationVisibility(SerializationVisibility.Hidden)]
		internal override SelectionPointsStyle SelectionPointsStyle
		{
			get
			{
				return SelectionPointsStyle.TwoPoints;
			}
		}

		[SRCategory("CategoryAttributeAppearance"), SRDescription("DescriptionAttributeStartCap3"), DefaultValue(0)]
		public virtual LineAnchorCapStyle StartCap
		{
			get
			{
				return this._startCap;
			}
			set
			{
				this._startCap = value;
				this.Invalidate();
			}
		}

		[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
		public override TextStyle TextStyle
		{
			get
			{
				return base.TextStyle;
			}
			set
			{
				base.TextStyle = value;
			}
		}
	}
}

